locals {
  nat_gw_groups = {
    nat_gateway = {
      gateway_name   = "nat_gateway-dev"
      spec           = "1"
      vpc_id         = data.terraform_remote_state.vpc.outputs.vpc_info.id
      subent_id      = data.terraform_remote_state.subnet.outputs.subnet_info["subnet-me212-dev-baidu_hub-natgateway"].id
      floating_ip_id = data.terraform_remote_state.eip.outputs.eip_info["eip_nat_gateway"].id
    }
  }
}

resource "huaweicloud_nat_gateway" "nat_gw" {
  for_each  = local.nat_gw_groups
  name      = each.value.gateway_name
  spec      = each.value.spec
  vpc_id    = each.value.vpc_id
  subnet_id = each.value.subent_id
}

/* resource "huaweicloud_nat_snat_rule" "nat_rule" {
  for_each       = local.nat_gw_groups
  nat_gateway_id = huaweicloud_nat_gateway.mod_nat_gw[each.key].id
  floating_ip_id = each.value.floating_ip_id
  subnet_id      = each.value.subent_id
  network_id = each.value.vpc_id
} */
resource "huaweicloud_nat_snat_rule" "rule_for_all_subnet" {
  for_each       = local.nat_gw_groups
  nat_gateway_id = huaweicloud_nat_gateway.nat_gw[each.key].id
  floating_ip_id = each.value.floating_ip_id
  source_type    = 1
  cidr           = data.terraform_remote_state.vpc.outputs.vpc_info.cidr
}